package com.mjf.scala.chapter06

/**
 * 存在继承关系，子类对象的创建过程
 */
object Scala10_TestExtends {

  def main(args: Array[String]): Unit = {

    // 自动类型推导 不能推导出多态
//    val std1: Person10 = new Student10()  // 1，3
//    val std2: Person10 = new Student10("lucy", 18, "1")  // 1，3，4
    val std3: Person10 = new Student10("lucy", 18, "1")  // 1，2，3，4
    println(std3.name)
  }

}

class Person10 {
  println("1-父类的主构造方法被调用了")

  var name: String = _
  var age: Int = _

  def this(name:String, age:Int) {
    this()
    println("2-父类的辅助构造方法被调用了")
    this.name = name
    this.age = age
  }
}

//class Student10 extends Person10 {    // 1,3,4
class Student10(name:String, age:Int) extends Person10(name, age) {
  println("3-子类的主构造方法被调用了")

  var stdNo: String = _

  def this(name:String, age:Int, stdNo:String) {
//    this()    // 1,3,4
    this(name, age)
    println("4-子类的辅助构造方法被调用了")
    this stdNo = stdNo
  }
}
